package com.weilan.blog.admin.controller;

import com.weilan.blog.admin.service.SysConfigService;
import com.weilan.blog.admin.vo.SysConfigVO;
import com.weilan.blog.common.global.SysConf;

import com.weilan.blog.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: 孙 峰
 * @time: 2020/10/10 15:59
 */
@RestController
@RequestMapping("/sysConfig")
public class SysConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 获取系统配置
     *
     * @return
     */
    @GetMapping("/getSysConfig")
    public String getSysConfig() {
        return ResultUtil.result(SysConf.SUCCESS, sysConfigService.getConfig());
    }


    /**
     * 通过Key前缀清空Redis缓存
     *
     * @param key
     * @return
     */
    @PostMapping("/cleanRedisByKey")
    public String cleanRedisByKey(@RequestBody List<String> key) {
        return sysConfigService.cleanRedisByKey(key);
    }

    /**
     * 修改系统配置
     *
     * @param sysConfigVO
     * @return
     */
    @PostMapping("/editSysConfig")
    public String editSysConfig(@RequestBody SysConfigVO sysConfigVO) {
        return sysConfigService.editSystemConfig(sysConfigVO);
    }
}
